package com.neo.office.server.controller.system;

import com.neo.office.server.config.data.Result;
import com.neo.office.server.domain.entity.Salary;
import com.neo.office.server.service.SalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @ApiOperation("获取所有工资账套")
    @GetMapping("/")
    public List<Salary> getAllSalary(){
        return salaryService.list();
    }

    @ApiOperation("添加工资账套")
    @PostMapping("/")
    public Result addSalary(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (salaryService.save(salary)){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }

    @ApiOperation("更新工资账套")
    @PutMapping("/")
    public Result updateSalary(@RequestBody Salary salary){
        if (salaryService.updateById(salary)){
            return Result.success("更新成功");
        }
        return Result.error("更新失败");
    }

    @ApiOperation("删除工资账套")
    @DeleteMapping("/{id}")
    public Result deleteSalary(@PathVariable Integer id){
        if (salaryService.removeById(id)){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

}
